package io.gitee.kotle.player.download

import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.offline.DownloadRequest

/**
 *
 * 描述：
 *
 * @author Jiale.Wei
 *
 * 创建时间：2023/4/27 17:56
 *
 */

/**
 * MediaItem 转 DownloadRequest
 */
fun MediaItem.toDownloadRequest(mediaId: String, data: ByteArray?): DownloadRequest {
    val configuration = localConfiguration
    val uri = configuration?.uri
        ?: throw java.lang.IllegalArgumentException("MediaItem uri is null: $this")
    return DownloadRequest.Builder(mediaId, uri)
        .setCustomCacheKey(configuration.customCacheKey)
        .setMimeType(configuration.mimeType)
        .setStreamKeys(configuration.streamKeys)
        .setData(data)
        .build()
}